/* 
 *项目常用工具函数集合
 */
//ajax同步获取数据返回
function ajaxSynchroRequest($url,$data=""){
    $result = "";
    $postdata = $data==""? {}:JSON.parse($data);
    $.ajax({
        //请求方式
        type : "GET",
        //请求的媒体类型
//        contentType: "application/json;charset=UTF-8",
        //请求地址
        async:false,
        url : $url,
        data : $postdata,
        //请求成功
        success : function(result) {
            $result = result;
        },
        //请求失败，包含具体的错误信息
        error : function(e){
            console.log(e.status);
            console.log(e.responseText);
        }
    });
    
    return $result;
}

function ajaxSynchroPostRequest($url,$data=""){
    $result = "";
    $postdata = $data==""? {}:JSON.parse($data);
    $.ajax({
        //请求方式
        type : "POST",
        //请求的媒体类型
//        contentType: "application/json;charset=UTF-8",
        //请求地址
        async:false,
        url : $url,
        data : $postdata,
        //请求成功
        success : function(result) {
            $result = result;
        },
        //请求失败，包含具体的错误信息
        error : function(e){
            console.log(e.status);
            console.log(e.responseText);
        }
    });
    
    return $result;
}

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
         }
         if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
         }
     }
    return "";
}

$(document).ready(function(){
    $('.btn-jump-url').on('click',function(){
        totalpage = $(this).attr('totalpage');
        page = $('#input-jump-url').val();
        if(parseInt(page) > parseInt(totalpage)){
            page = 1;
        }
        window.location.href = $(this).attr('tourl')+page;
    });
});
